package com.example.zhugenew.fragment;

import android.os.Bundle;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.example.mymvplibrary.ui.fragment.BaseMvpFramgent;
import com.example.zhugenew.R;
import com.example.zhugenew.adapter.InforVpAdapter;
import com.example.zhugenew.bean.NewTypeListBean;
import com.example.zhugenew.concation.MainConations;
import com.example.zhugenew.model.HomeModel;
import com.example.zhugenew.presenter.HomePresenter;
import com.google.android.material.tabs.TabLayout;
import com.google.gson.Gson;
import com.google.gson.JsonElement;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;

public class InformationFragment<T> extends BaseMvpFramgent<MainConations.MainView, HomeModel, HomePresenter<T>> implements MainConations.MainView<T> {

    @BindView(R.id.infor_tablayout)
    TabLayout inforTablayout;
    @BindView(R.id.infor_vp)
    ViewPager inforVp;
    private String TAG = "cjh";
    private List<NewTypeListBean.ListBean> list;

    @Override
    protected HomePresenter<T> createPresenter() {
        return new HomePresenter();
    }

    @Override
    protected void initEvent() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("platformType", "4");


        mPerter.getData("contentService/v1/News/appNewsTypeList", 0, map);
    }

    @Override
    protected int createLayoutId() {
        return R.layout.fragment_information;
    }

    @Override
    public void showList(T t, int type) {
//
//        ArrayList<String> strings = new ArrayList<>();
//        ArrayList<Fragment> fragments = new ArrayList<>();
//        Log.e(TAG, "showList: " +t.toString());
//        NewTypeListBean newTypeListBean = new Gson().fromJson((JsonElement) t, NewTypeListBean.class);
//
//        list = newTypeListBean.getList();
//        Log.e(TAG, "showList: " + list.size());
//        for (int i = 0; i < list.size(); i++) {
//            RecommendedFragment recommendedFragment = new RecommendedFragment();
//            fragments.add(recommendedFragment);
//            String url = list.get(i).getUrl();
//            Bundle bundle = new Bundle();
//            bundle.putString("url", url);
//            recommendedFragment.setArguments(bundle);
//            strings.add(list.get(i).getTitle());
//        }
//        Log.e(TAG, "showList: " + fragments.size());
        ArrayList<Fragment> fragments = new ArrayList<>();
        fragments.add(new RecommendedFragment());
        fragments.add(new ImportantFragment());
        fragments.add(new EncyclopediaFragment());
        fragments.add(new MarketFragment());
        fragments.add(new RealFragment());
        ArrayList<String> strings = new ArrayList<>();
        strings.add("推荐");
        strings.add("要闻");
        strings.add("百科");
        strings.add("市场报告");
        strings.add("楼市动态");
        InforVpAdapter inforVpAdapter = new InforVpAdapter(getChildFragmentManager(), fragments, strings);
        inforVp.setAdapter(inforVpAdapter);
        inforTablayout.setupWithViewPager(inforVp);

    }

    @Override
    public void showError(String error, int code) {

    }

    @Override
    public void showProgressbar() {

    }

    @Override
    public void hideProgressbar() {

    }
}